package com.dzsw.boot.mpvs;

import com.dzsw.boot.protocol.Person;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyAccessorFactory;

public class MutablePropertyValuesSample {

    public static void main(String[] args) {
        // 定义属性名称和对应值
        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.addPropertyValue("id", 100);
        mutablePropertyValues.addPropertyValue("name", "Judy");
        // 创建对象，并注入属性和值，只能注入类有的值
        Person person = new Person();
        System.out.println(person);
        BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(person);
        beanWrapper.setPropertyValues(mutablePropertyValues);
        System.out.println(person);

    }

}
